package com.zjzywl.smoke.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zjzywl.smoke.repository.DeviceRepository;
import com.zjzywl.smoke.util.WebResult;
import com.zjzywl.smoke.entity.Device;

@RestController
@RequestMapping(value = "/internal")
public class InternalController extends BaseController {

	@Autowired
	private DeviceRepository deviceRepository;

	@RequestMapping(value = "/setposition")
	public String showMapToSetDevicePosition() {
		return "manage/changeMapPoint";
	}

	@PostMapping(value = "/device/position/save")
	 
	public WebResult ProofingPosition(@RequestParam("devCode") String devCode, @RequestParam("lon") String lon,
			@RequestParam("lat") String lat) {
		Device device = deviceRepository.findByDeviceCode(devCode);

		if ((device != null) && (lon.length() > 0) && (lat.length() > 0)) {
			device.setLongitude(Double.parseDouble(lon));
			device.setLatitude(Double.parseDouble(lat));
			deviceRepository.save(device);
			return WebResult.OK();
		} else {
			return WebResult.FAIL("上报的数据有误！");
		}
   
	}

}
